/*
 * Copyright 2007-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.paoding.rose.web.msg;

/**
 * 
 * @author zhiliang.wang [qieqie.wang@gmail.com]
 * 
 */
public class StringManagerAdapter {

	protected StringManager stringManager;

	public StringManagerAdapter(StringManager stringManager) {
		this.stringManager = stringManager;
	}

	/**
	 * Get a string from the underlying resource bundle or return null if the
	 * String is not found.
	 * 
	 * @param key
	 *            to desired resource String
	 * @return resource String matching <i>key</i> from underlying bundle or
	 *         null if not found. @
	 * @throws IllegalArgumentException
	 *             if <i>key</i> is null.
	 */
	public String get(String key) {
		return key(key, (Object[]) null);
	}

	public String key(String key) {
		return key(key, (Object[]) null);
	}

	/**
	 * Get a string from the underlying resource bundle and format it with the
	 * given object argument. This argument can of course be a String object.
	 * 
	 * @param key
	 * @param arg
	 */

	public String get(String key, Object arg) {
		Object[] args = new Object[] { arg };
		return key(key, args);
	}

	public String key(String key, Object arg) {
		Object[] args = new Object[] { arg };
		return key(key, args);
	}

	/**
	 * Get a string from the underlying resource bundle and format it with the
	 * given object arguments. These arguments can of course be String objects.
	 * 
	 * @param key
	 * @param arg
	 * @param arg
	 */

	public String get(String key, Object arg, Object arg1) {
		Object[] args = new Object[] { arg, arg1 };
		return key(key, args);
	}

	public String key(String key, Object arg, Object arg1) {
		Object[] args = new Object[] { arg, arg1 };
		return key(key, args);
	}

	/**
	 * Get a string from the underlying resource bundle and format it with the
	 * given object arguments. These arguments can of course be String objects.
	 * 
	 * @param key
	 * @param arg
	 * @param arg
	 * @param arg
	 */

	public String get(String key, Object arg, Object arg1, Object arg2) {
		Object[] args = new Object[] { arg, arg1, arg2 };
		return key(key, args);
	}

	public String key(String key, Object arg, Object arg1, Object arg2) {
		Object[] args = new Object[] { arg, arg1, arg2 };
		return key(key, args);
	}

	/**
	 * Get a string from the underlying resource bundle and format it with the
	 * given object arguments. These arguments can of course be String objects.
	 * 
	 * @param key
	 * @param arg
	 * @param arg
	 * @param arg
	 * @param arg
	 */

	public String key(String key, Object arg, Object arg1, Object arg2, Object arg3) {
		Object[] args = new Object[] { arg, arg1, arg2, arg3 };
		return key(key, args);
	}

	public String get(String key, Object arg, Object arg1, Object arg2, Object arg3) {
		Object[] args = new Object[] { arg, arg1, arg2, arg3 };
		return key(key, args);
	}

	public String key(String key, Object[] args) {
		if (args == null || args.length == 0) {
			return stringManager.getString(key);
		}
		return stringManager.getString(key, args);
	}
}
